package com.wzq.animal.common.config;


import cn.hutool.core.collection.ListUtil;
import com.wzq.animal.common.interceptor.JWTInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> whiteUrl = new ArrayList<>();
        whiteUrl.add("/login");
        whiteUrl.add("/register");
        whiteUrl.add("/import");
        whiteUrl.add("/export");
        whiteUrl.add("/animal/**");
        whiteUrl.add("/news/**");
        whiteUrl.add("/notice/**");
        whiteUrl.add("/scenic/**");
        whiteUrl.add("/swiper/**");
        whiteUrl.add("/website/**");
        whiteUrl.add("/files/**");
        whiteUrl.add("/getCode");
        whiteUrl.add("/checkCode/**");
        whiteUrl.add("/apply/**");
        whiteUrl.add("/resetPassword/**");
        whiteUrl.add("/getEmailCode/**");
        whiteUrl.add("/resetPassByEmail/**");
        registry.addInterceptor(jwtInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(whiteUrl);

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //配置拦截器访问静态资源
        //registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        //registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/META-INF/resources/");
        //registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    @Bean
    public JWTInterceptor jwtInterceptor() {
        return new JWTInterceptor();
    }
}
